import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TurnManager {
    JButton Pass;/*过回合*/
    JButton PlayACard;
    JButton PlatACardToTail;
    public static TurnManager Instance = new TurnManager();
    public void Init(){
        Pass = new JButton("过");
        PlayACard = new JButton("出牌(首)");
        PlatACardToTail = new JButton("出牌(尾)");
        Pass.setBounds(1250,700,100,60);
        PlayACard.setBounds(1250,790,100,60);
        PlatACardToTail.setBounds(1250,880,100,60);
        Pass.setVisible(true);
        PlayACard.setVisible(true);
        PlatACardToTail.setVisible(true);
        PlayACard.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                GamePanel.Instance.isFollowHead = true;
                GamePanel.Instance.isFollowTail= false;
                //System.out.println("Play a card clicked");
                DialogJudge();
            }
        });
        PlatACardToTail.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //System.out.println("Play a card clicked");
                GamePanel.Instance.isFollowTail = true;
                GamePanel.Instance.isFollowHead = false;
                DialogJudge();
            }
        });
        Pass.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("Pass Clicked");
            }
        });
    }

    public void DialogJudge() {
        if(MyLibrary.SelectedDominoes == null){
            //JOptionPane.showMessageDialog(null,"请选择一张骨牌！");
            new NoBorderDialog("请选择一张骨牌！");
            return;
        }
        if(!GamePanel.Instance.Judge(MyLibrary.SelectedDominoes)){
            new NoBorderDialog("接不上哦");
            return;
        }

        GamePanel.Instance.PutDominoes(MyLibrary.SelectedDominoes.name);
    }
}
